//
// Created by 29001 on 2024/11/21.
//

#ifndef HANDWRITTEN_SQLITE_ROW_H
#define HANDWRITTEN_SQLITE_ROW_H

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>
#include <errno.h>
#include <stdint.h>

#define COLUMN_USERNAME_SIZE 32
#define COLUMN_EMAIL_SIZE 255

/*
 * define a row of a table
 */
typedef struct {
    uint32_t id;
    char username[COLUMN_USERNAME_SIZE];
    char email[COLUMN_EMAIL_SIZE];
} Row;

/*
 * define row's field
 */
#define size_of_attribute(struct, Attribute) sizeof(((struct*)0)->Attribute)// casts the 0(NULL) pointer to type struct*.

const uint32_t ID_SIZE = size_of_attribute(Row, id);// size
const uint32_t USERNAME_SIZE = size_of_attribute(Row, username);
const uint32_t EMAIL_SIZE = size_of_attribute(Row, email);
const uint32_t ID_OFFSET = 0;
const uint32_t USERNAME_OFFSET = ID_OFFSET + ID_SIZE;//address offset
const uint32_t EMAIL_OFFSET = USERNAME_OFFSET + USERNAME_SIZE;
const uint32_t ROW_SIZE = ID_SIZE + USERNAME_SIZE + EMAIL_SIZE;

/*
 * here move row data to specially memory
 */
void serialize_row(Row *source, void *destination);

void deserialize_row(void *source, Row *destination);


/*
 * here print the row of the table
 */
void print_row(Row *row);

#endif //HANDWRITTEN_SQLITE_ROW_H
